<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PEM_read_bio_PrivateKey</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>



<ul id="index">
  <li><a href="#NAME">NAME</a></li>
  <li><a href="#SYNOPSIS">SYNOPSIS</a></li>
  <li><a href="#DESCRIPTION">DESCRIPTION</a></li>
  <li><a href="#PEM-FUNCTION-ARGUMENTS">PEM FUNCTION ARGUMENTS</a></li>
  <li><a href="#NOTES">NOTES</a></li>
  <li><a href="#PEM-ENCRYPTION-FORMAT">PEM ENCRYPTION FORMAT</a></li>
  <li><a href="#BUGS">BUGS</a></li>
  <li><a href="#RETURN-VALUES">RETURN VALUES</a></li>
  <li><a href="#EXAMPLES">EXAMPLES</a></li>
  <li><a href="#SEE-ALSO">SEE ALSO</a></li>
  <li><a href="#HISTORY">HISTORY</a></li>
  <li><a href="#COPYRIGHT">COPYRIGHT</a></li>
</ul>

<h1 id="NAME">NAME</h1>

<p>pem_password_cb, PEM_read_bio_PrivateKey, PEM_read_PrivateKey, PEM_write_bio_PrivateKey, PEM_write_bio_PrivateKey_traditional, PEM_write_PrivateKey, PEM_write_bio_PKCS8PrivateKey, PEM_write_PKCS8PrivateKey, PEM_write_bio_PKCS8PrivateKey_nid, PEM_write_PKCS8PrivateKey_nid, PEM_read_bio_PUBKEY, PEM_read_PUBKEY, PEM_write_bio_PUBKEY, PEM_write_PUBKEY, PEM_read_bio_RSAPrivateKey, PEM_read_RSAPrivateKey, PEM_write_bio_RSAPrivateKey, PEM_write_RSAPrivateKey, PEM_read_bio_RSAPublicKey, PEM_read_RSAPublicKey, PEM_write_bio_RSAPublicKey, PEM_write_RSAPublicKey, PEM_read_bio_RSA_PUBKEY, PEM_read_RSA_PUBKEY, PEM_write_bio_RSA_PUBKEY, PEM_write_RSA_PUBKEY, PEM_read_bio_DSAPrivateKey, PEM_read_DSAPrivateKey, PEM_write_bio_DSAPrivateKey, PEM_write_DSAPrivateKey, PEM_read_bio_DSA_PUBKEY, PEM_read_DSA_PUBKEY, PEM_write_bio_DSA_PUBKEY, PEM_write_DSA_PUBKEY, PEM_read_bio_DSAparams, PEM_read_DSAparams, PEM_write_bio_DSAparams, PEM_write_DSAparams, PEM_read_bio_DHparams, PEM_read_DHparams, PEM_write_bio_DHparams, PEM_write_DHparams, PEM_read_bio_X509, PEM_read_X509, PEM_write_bio_X509, PEM_write_X509, PEM_read_bio_X509_AUX, PEM_read_X509_AUX, PEM_write_bio_X509_AUX, PEM_write_X509_AUX, PEM_read_bio_X509_REQ, PEM_read_X509_REQ, PEM_write_bio_X509_REQ, PEM_write_X509_REQ, PEM_write_bio_X509_REQ_NEW, PEM_write_X509_REQ_NEW, PEM_read_bio_X509_CRL, PEM_read_X509_CRL, PEM_write_bio_X509_CRL, PEM_write_X509_CRL, PEM_read_bio_PKCS7, PEM_read_PKCS7, PEM_write_bio_PKCS7, PEM_write_PKCS7 - PEM routines</p>

<h1 id="SYNOPSIS">SYNOPSIS</h1>

<pre><code> <span class="comment">#include &lt;openssl/pem.h&gt;</span>
 
 <span class="variable">typedef</span> <span class="keyword">int</span> <span class="variable">pem_password_cb</span><span class="operator">(</span><span class="variable">char</span> <span class="variable">*buf</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">size</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">rwflag</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 
 <span class="variable">EVP_PKEY</span> <span class="variable">*PEM_read_bio_PrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="operator">**x,</span>
                                   <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">EVP_PKEY</span> <span class="variable">*PEM_read_PrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="operator">**x,</span>
                               <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                              <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                              <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PrivateKey_traditional</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span>
                                          <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                                          <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                          <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_PrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                          <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                          <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PKCS8PrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                                   <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                   <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_PKCS8PrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                               <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                               <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PKCS8PrivateKey_nid</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">nid</span><span class="operator">,</span>
                                       <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                       <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_PKCS8PrivateKey_nid</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">nid</span><span class="operator">,</span>
                                   <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                   <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 
 <span class="variable">EVP_PKEY</span> <span class="variable">*PEM_read_bio_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="operator">**x,</span>
                               <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">EVP_PKEY</span> <span class="variable">*PEM_read_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="operator">**x,</span>
                           <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">EVP_PKEY</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">RSA</span> <span class="variable">*PEM_read_bio_RSAPrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">RSA</span> <span class="variable">*PEM_read_RSAPrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_RSAPrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                                 <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_RSAPrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                             <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 
 <span class="variable">RSA</span> <span class="variable">*PEM_read_bio_RSAPublicKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                                <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">RSA</span> <span class="variable">*PEM_read_RSAPublicKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                            <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_RSAPublicKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_RSAPublicKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">RSA</span> <span class="variable">*PEM_read_bio_RSA_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                              <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">RSA</span> <span class="variable">*PEM_read_RSA_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="operator">**x,</span>
                          <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_RSA_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_RSA_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">RSA</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">DSA</span> <span class="variable">*PEM_read_bio_DSAPrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">DSA</span> <span class="variable">*PEM_read_DSAPrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_DSAPrivateKey</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                                 <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_DSAPrivateKey</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">,</span> <span class="variable">const</span> <span class="variable">EVP_CIPHER</span> <span class="variable">*enc</span><span class="operator">,</span>
                             <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">*kstr</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">klen</span><span class="operator">,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 
 <span class="variable">DSA</span> <span class="variable">*PEM_read_bio_DSA_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span>
                              <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">DSA</span> <span class="variable">*PEM_read_DSA_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span>
                          <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_DSA_PUBKEY</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_DSA_PUBKEY</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">DSA</span> <span class="variable">*PEM_read_bio_DSAparams</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">DSA</span> <span class="variable">*PEM_read_DSAparams</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_DSAparams</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_DSAparams</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DSA</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">DH</span> <span class="variable">*PEM_read_bio_DHparams</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DH</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">DH</span> <span class="variable">*PEM_read_DHparams</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DH</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_DHparams</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">DH</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_DHparams</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">DH</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">X509</span> <span class="variable">*PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">X509</span> <span class="variable">*PEM_read_X509</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_X509</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_X509</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">X509</span> <span class="variable">*PEM_read_bio_X509_AUX</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">X509</span> <span class="variable">*PEM_read_X509_AUX</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_X509_AUX</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_X509_AUX</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">X509_REQ</span> <span class="variable">*PEM_read_bio_X509_REQ</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="operator">**x,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">X509_REQ</span> <span class="variable">*PEM_read_X509_REQ</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="operator">**x,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_X509_REQ</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_X509_REQ</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_X509_REQ_NEW</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_X509_REQ_NEW</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509_REQ</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">X509_CRL</span> <span class="variable">*PEM_read_bio_X509_CRL</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509_CRL</span> <span class="operator">**x,</span>
                                 <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">X509_CRL</span> <span class="variable">*PEM_read_X509_CRL</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509_CRL</span> <span class="operator">**x,</span>
                             <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_X509_CRL</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">X509_CRL</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_X509_CRL</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">X509_CRL</span> <span class="variable">*x</span><span class="operator">);</span>
 
 <span class="variable">PKCS7</span> <span class="variable">*PEM_read_bio_PKCS7</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">PKCS7</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="variable">PKCS7</span> <span class="variable">*PEM_read_PKCS7</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">PKCS7</span> <span class="operator">**x,</span> <span class="variable">pem_password_cb</span> <span class="variable">*cb</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_bio_PKCS7</span><span class="operator">(</span><span class="variable">BIO</span> <span class="variable">*bp</span><span class="operator">,</span> <span class="variable">PKCS7</span> <span class="variable">*x</span><span class="operator">);</span>
 <span class="keyword">int</span> <span class="variable">PEM_write_PKCS7</span><span class="operator">(</span><span class="variable">FILE</span> <span class="variable">*fp</span><span class="operator">,</span> <span class="variable">PKCS7</span> <span class="variable">*x</span><span class="operator">);</span>
</code></pre>

<h1 id="DESCRIPTION">DESCRIPTION</h1>

<p>The PEM functions read or write structures in PEM format. In this sense PEM format is simply base64 encoded data surrounded by header lines.</p>

<p>For more details about the meaning of arguments see the <b>PEM FUNCTION ARGUMENTS</b> section.</p>

<p>Each operation has four functions associated with it. For brevity the term &quot;<b>TYPE</b> functions&quot; will be used below to collectively refer to the PEM_read_bio_TYPE(), PEM_read_TYPE(), PEM_write_bio_TYPE(), and PEM_write_TYPE() functions.</p>

<p>The <b>PrivateKey</b> functions read or write a private key in PEM format using an EVP_PKEY structure. The write routines use PKCS#8 private key format and are equivalent to PEM_write_bio_PKCS8PrivateKey().The read functions transparently handle traditional and PKCS#8 format encrypted and unencrypted keys.</p>

<p>PEM_write_bio_PrivateKey_traditional() writes out a private key in the &quot;traditional&quot; format with a simple private key marker and should only be used for compatibility with legacy programs.</p>

<p>PEM_write_bio_PKCS8PrivateKey() and PEM_write_PKCS8PrivateKey() write a private key in an EVP_PKEY structure in PKCS#8 EncryptedPrivateKeyInfo format using PKCS#5 v2.0 password based encryption algorithms. The <b>cipher</b> argument specifies the encryption algorithm to use: unlike some other PEM routines the encryption is applied at the PKCS#8 level and not in the PEM headers. If <b>cipher</b> is NULL then no encryption is used and a PKCS#8 PrivateKeyInfo structure is used instead.</p>

<p>PEM_write_bio_PKCS8PrivateKey_nid() and PEM_write_PKCS8PrivateKey_nid() also write out a private key as a PKCS#8 EncryptedPrivateKeyInfo however it uses PKCS#5 v1.5 or PKCS#12 encryption algorithms instead. The algorithm to use is specified in the <b>nid</b> parameter and should be the NID of the corresponding OBJECT IDENTIFIER (see NOTES section).</p>

<p>The <b>PUBKEY</b> functions process a public key using an EVP_PKEY structure. The public key is encoded as a SubjectPublicKeyInfo structure.</p>

<p>The <b>RSAPrivateKey</b> functions process an RSA private key using an RSA structure. The write routines uses traditional format. The read routines handles the same formats as the <b>PrivateKey</b> functions but an error occurs if the private key is not RSA.</p>

<p>The <b>RSAPublicKey</b> functions process an RSA public key using an RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey structure.</p>

<p>The <b>RSA_PUBKEY</b> functions also process an RSA public key using an RSA structure. However the public key is encoded using a SubjectPublicKeyInfo structure and an error occurs if the public key is not RSA.</p>

<p>The <b>DSAPrivateKey</b> functions process a DSA private key using a DSA structure. The write routines uses traditional format. The read routines handles the same formats as the <b>PrivateKey</b> functions but an error occurs if the private key is not DSA.</p>

<p>The <b>DSA_PUBKEY</b> functions process a DSA public key using a DSA structure. The public key is encoded using a SubjectPublicKeyInfo structure and an error occurs if the public key is not DSA.</p>

<p>The <b>DSAparams</b> functions process DSA parameters using a DSA structure. The parameters are encoded using a Dss-Parms structure as defined in RFC2459.</p>

<p>The <b>DHparams</b> functions process DH parameters using a DH structure. The parameters are encoded using a PKCS#3 DHparameter structure.</p>

<p>The <b>X509</b> functions process an X509 certificate using an X509 structure. They will also process a trusted X509 certificate but any trust settings are discarded.</p>

<p>The <b>X509_AUX</b> functions process a trusted X509 certificate using an X509 structure.</p>

<p>The <b>X509_REQ</b> and <b>X509_REQ_NEW</b> functions process a PKCS#10 certificate request using an X509_REQ structure. The <b>X509_REQ</b> write functions use <b>CERTIFICATE REQUEST</b> in the header whereas the <b>X509_REQ_NEW</b> functions use <b>NEW CERTIFICATE REQUEST</b> (as required by some CAs). The <b>X509_REQ</b> read functions will handle either form so there are no <b>X509_REQ_NEW</b> read functions.</p>

<p>The <b>X509_CRL</b> functions process an X509 CRL using an X509_CRL structure.</p>

<p>The <b>PKCS7</b> functions process a PKCS#7 ContentInfo using a PKCS7 structure.</p>

<h1 id="PEM-FUNCTION-ARGUMENTS">PEM FUNCTION ARGUMENTS</h1>

<p>The PEM functions have many common arguments.</p>

<p>The <b>bp</b> BIO parameter (if present) specifies the BIO to read from or write to.</p>

<p>The <b>fp</b> FILE parameter (if present) specifies the FILE pointer to read from or write to.</p>

<p>The PEM read functions all take an argument <b>TYPE **x</b> and return a <b>TYPE *</b> pointer. Where <b>TYPE</b> is whatever structure the function uses. If <b>x</b> is NULL then the parameter is ignored. If <b>x</b> is not NULL but <b>*x</b> is NULL then the structure returned will be written to <b>*x</b>. If neither <b>x</b> nor <b>*x</b> is NULL then an attempt is made to reuse the structure at <b>*x</b> (but see BUGS and EXAMPLES sections). Irrespective of the value of <b>x</b> a pointer to the structure is always returned (or NULL if an error occurred).</p>

<p>The PEM functions which write private keys take an <b>enc</b> parameter which specifies the encryption algorithm to use, encryption is done at the PEM level. If this parameter is set to NULL then the private key is written in unencrypted form.</p>

<p>The <b>cb</b> argument is the callback to use when querying for the pass phrase used for encrypted PEM structures (normally only private keys).</p>

<p>For the PEM write routines if the <b>kstr</b> parameter is not NULL then <b>klen</b> bytes at <b>kstr</b> are used as the passphrase and <b>cb</b> is ignored.</p>

<p>If the <b>cb</b> parameters is set to NULL and the <b>u</b> parameter is not NULL then the <b>u</b> parameter is interpreted as a null terminated string to use as the passphrase. If both <b>cb</b> and <b>u</b> are NULL then the default callback routine is used which will typically prompt for the passphrase on the current terminal with echoing turned off.</p>

<p>The default passphrase callback is sometimes inappropriate (for example in a GUI application) so an alternative can be supplied. The callback routine has the following form:</p>

<pre><code> <span class="keyword">int</span> <span class="variable">cb</span><span class="operator">(</span><span class="variable">char</span> <span class="variable">*buf</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">size</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">rwflag</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">);</span>
</code></pre>

<p><b>buf</b> is the buffer to write the passphrase to. <b>size</b> is the maximum length of the passphrase (i.e. the size of buf). <b>rwflag</b> is a flag which is set to 0 when reading and 1 when writing. A typical routine will ask the user to verify the passphrase (for example by prompting for it twice) if <b>rwflag</b> is 1. The <b>u</b> parameter has the same value as the <b>u</b> parameter passed to the PEM routine. It allows arbitrary data to be passed to the callback by the application (for example a window handle in a GUI application). The callback <b>must</b> return the number of characters in the passphrase or -1 if an error occurred.</p>

<h1 id="NOTES">NOTES</h1>

<p>The old <b>PrivateKey</b> write routines are retained for compatibility. New applications should write private keys using the PEM_write_bio_PKCS8PrivateKey() or PEM_write_PKCS8PrivateKey() routines because they are more secure (they use an iteration count of 2048 whereas the traditional routines use a count of 1) unless compatibility with older versions of OpenSSL is important.</p>

<p>The <b>PrivateKey</b> read routines can be used in all applications because they handle all formats transparently.</p>

<p>A frequent cause of problems is attempting to use the PEM routines like this:</p>

<pre><code> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">;</span>
 
 <span class="variable">PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="operator">&amp;x,</span> <span class="number">0</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">);</span>
</code></pre>

<p>this is a bug because an attempt will be made to reuse the data at <b>x</b> which is an uninitialised pointer.</p>

<p>These functions make no assumption regarding the pass phrase received from the password callback. It will simply be treated as a byte sequence.</p>

<h1 id="PEM-ENCRYPTION-FORMAT">PEM ENCRYPTION FORMAT</h1>

<p>These old <b>PrivateKey</b> routines use a non standard technique for encryption.</p>

<p>The private key (or other data) takes the following form:</p>

<pre><code> -----BEGIN RSA PRIVATE KEY-----
 Proc-Type: 4,ENCRYPTED
 DEK-Info: DES-EDE3-CBC,3F17F5316E2BAC89

 ...base64 encoded data...
 -----END RSA PRIVATE KEY-----</code></pre>

<p>The line beginning with <i>Proc-Type</i> contains the version and the protection on the encapsulated data. The line beginning <i>DEK-Info</i> contains two comma separated values: the encryption algorithm name as used by EVP_get_cipherbyname() and an initialization vector used by the cipher encoded as a set of hexadecimal digits. After those two lines is the base64-encoded encrypted data.</p>

<p>The encryption key is derived using EVP_BytesToKey(). The cipher&#39;s initialization vector is passed to EVP_BytesToKey() as the <b>salt</b> parameter. Internally, <b>PKCS5_SALT_LEN</b> bytes of the salt are used (regardless of the size of the initialization vector). The user&#39;s password is passed to EVP_BytesToKey() using the <b>data</b> and <b>datal</b> parameters. Finally, the library uses an iteration count of 1 for EVP_BytesToKey().</p>

<p>The <b>key</b> derived by EVP_BytesToKey() along with the original initialization vector is then used to decrypt the encrypted data. The <b>iv</b> produced by EVP_BytesToKey() is not utilized or needed, and NULL should be passed to the function.</p>

<p>The pseudo code to derive the key would look similar to:</p>

<pre><code> <span class="variable">EVP_CIPHER</span><span class="operator">*</span> <span class="variable">cipher</span> <span class="operator">=</span> <span class="variable">EVP_des_ede3_cbc</span><span class="operator">();</span>
 <span class="variable">EVP_MD</span><span class="operator">*</span> <span class="variable">md</span> <span class="operator">=</span> <span class="variable">EVP_md5</span><span class="operator">();</span>
 
 <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">nkey</span> <span class="operator">=</span> <span class="variable">EVP_CIPHER_key_length</span><span class="operator">(</span><span class="variable">cipher</span><span class="operator">);</span>
 <span class="variable">unsigned</span> <span class="keyword">int</span> <span class="variable">niv</span> <span class="operator">=</span> <span class="variable">EVP_CIPHER_iv_length</span><span class="operator">(</span><span class="variable">cipher</span><span class="operator">);</span>
 <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">key</span><span class="operator">[</span><span class="variable">nkey</span><span class="operator">]</span><span class="operator">;</span>
 <span class="variable">unsigned</span> <span class="variable">char</span> <span class="variable">iv</span><span class="operator">[</span><span class="variable">niv</span><span class="operator">]</span><span class="operator">;</span>
 
 <span class="variable">memcpy</span><span class="operator">(</span><span class="variable">iv</span><span class="operator">,</span> <span class="variable">HexToBin</span><span class="operator">(</span><span class="string">"3F17F5316E2BAC89"</span><span class="operator">),</span> <span class="variable">niv</span><span class="operator">);</span>
 <span class="variable">rc</span> <span class="operator">=</span> <span class="variable">EVP_BytesToKey</span><span class="operator">(</span><span class="variable">cipher</span><span class="operator">,</span> <span class="variable">md</span><span class="operator">,</span> <span class="variable">iv</span> <span class="operator">/</span><span class="variable">*salt</span><span class="operator">*/,</span> <span class="variable">pword</span><span class="operator">,</span> <span class="variable">plen</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="variable">key</span><span class="operator">,</span> <span class="variable">NULL</span> <span class="operator">/</span><span class="variable">*iv</span><span class="operator">*/);</span>
 <span class="keyword">if</span> <span class="operator">(</span><span class="variable">rc</span> <span class="operator">!=</span> <span class="variable">nkey</span><span class="operator">)</span>
     <span class="operator">/*</span> <span class="variable">Error</span> <span class="operator">*/</span>
 
 <span class="regex">/* On success, use key and iv to initialize the cipher */</span>
</code></pre>

<h1 id="BUGS">BUGS</h1>

<p>The PEM read routines in some versions of OpenSSL will not correctly reuse an existing structure. Therefore the following:</p>

<pre><code> <span class="variable">PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="operator">&amp;x,</span> <span class="number">0</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">);</span>
</code></pre>

<p>where <b>x</b> already contains a valid certificate, may not work, whereas:</p>

<pre><code> <span class="variable">X509_free</span><span class="operator">(x);</span>
 <span class="operator">x</span> <span class="operator">=</span> <span class="variable">PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">);</span>
</code></pre>

<p>is guaranteed to work.</p>

<h1 id="RETURN-VALUES">RETURN VALUES</h1>

<p>The read routines return either a pointer to the structure read or NULL if an error occurred.</p>

<p>The write routines return 1 for success or 0 for failure.</p>

<h1 id="EXAMPLES">EXAMPLES</h1>

<p>Although the PEM routines take several arguments in almost all applications most of them are set to 0 or NULL.</p>

<p>Read a certificate in PEM format from a BIO:</p>

<pre><code> <span class="variable">X509</span> <span class="variable">*x</span><span class="operator">;</span>
 
 <span class="operator">x</span> <span class="operator">=</span> <span class="variable">PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">);</span>
 <span class="keyword">if</span> <span class="operator">(x</span> <span class="operator">==</span> <span class="variable">NULL</span><span class="operator">)</span>
     <span class="operator">/*</span> <span class="variable">Error</span> <span class="operator">*/</span>
</code></pre>

<p>Alternative method:</p>

<pre><code> <span class="variable">X509</span> <span class="variable">*x</span> <span class="operator">=</span> <span class="variable">NULL</span><span class="operator">;</span>
 
 <span class="keyword">if</span> <span class="operator">(!</span><span class="variable">PEM_read_bio_X509</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="operator">&amp;x,</span> <span class="number">0</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">))</span>
     <span class="operator">/*</span> <span class="variable">Error</span> <span class="operator">*/</span>
</code></pre>

<p>Write a certificate to a BIO:</p>

<pre><code> if (!PEM_write_bio_X509(bp, x))
     /* Error */</code></pre>

<p>Write a private key (using traditional format) to a BIO using triple DES encryption, the pass phrase is prompted for:</p>

<pre><code> if (!PEM_write_bio_PrivateKey(bp, key, EVP_des_ede3_cbc(), NULL, 0, 0, NULL))
     /* Error */</code></pre>

<p>Write a private key (using PKCS#8 format) to a BIO using triple DES encryption, using the pass phrase &quot;hello&quot;:</p>

<pre><code> if (!PEM_write_bio_PKCS8PrivateKey(bp, key, EVP_des_ede3_cbc(),
                                    NULL, 0, 0, &quot;hello&quot;))
     /* Error */</code></pre>

<p>Read a private key from a BIO using a pass phrase callback:</p>

<pre><code> <span class="variable">key</span> <span class="operator">=</span> <span class="variable">PEM_read_bio_PrivateKey</span><span class="operator">(</span><span class="variable">bp</span><span class="operator">,</span> <span class="variable">NULL</span><span class="operator">,</span> <span class="variable">pass_cb</span><span class="operator">,</span> <span class="string">"My Private Key"</span><span class="operator">);</span>
 <span class="keyword">if</span> <span class="operator">(</span><span class="variable">key</span> <span class="operator">==</span> <span class="variable">NULL</span><span class="operator">)</span>
     <span class="operator">/*</span> <span class="variable">Error</span> <span class="operator">*/</span>
</code></pre>

<p>Skeleton pass phrase callback:</p>

<pre><code> <span class="keyword">int</span> <span class="variable">pass_cb</span><span class="operator">(</span><span class="variable">char</span> <span class="variable">*buf</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">size</span><span class="operator">,</span> <span class="keyword">int</span> <span class="variable">rwflag</span><span class="operator">,</span> <span class="variable">void</span> <span class="variable">*u</span><span class="operator">)</span>
 <span class="operator">{</span>
 
     <span class="regex">/* We'd probably do something else if 'rwflag' is 1 */</span>
     <span class="keyword">printf</span><span class="operator">(</span><span class="string">"Enter pass phrase for \"%s\"\n"</span><span class="operator">,</span> <span class="operator">(</span><span class="variable">char</span> <span class="operator">*)</span><span class="variable">u</span><span class="operator">);</span>
 
     <span class="regex">/* get pass phrase, length 'len' into 'tmp' */</span>
     <span class="variable">char</span> <span class="variable">*tmp</span> <span class="operator">=</span> <span class="string">"hello"</span><span class="operator">;</span>
     <span class="keyword">if</span> <span class="operator">(</span><span class="variable">tmp</span> <span class="operator">==</span> <span class="variable">NULL</span><span class="operator">)</span> <span class="operator">/*</span> <span class="variable">An</span> <span class="variable">error</span> <span class="variable">occurred</span> <span class="operator">*/</span>
         <span class="keyword">return</span> <span class="operator">-</span><span class="number">1</span><span class="operator">;</span>
 
     <span class="variable">size_t</span> <span class="variable">len</span> <span class="operator">=</span> <span class="variable">strlen</span><span class="operator">(</span><span class="variable">tmp</span><span class="operator">);</span>
 
     <span class="keyword">if</span> <span class="operator">(</span><span class="variable">len</span> <span class="operator">&gt;</span> <span class="variable">size</span><span class="operator">)</span>
         <span class="variable">len</span> <span class="operator">=</span> <span class="variable">size</span><span class="operator">;</span>
     <span class="variable">memcpy</span><span class="operator">(</span><span class="variable">buf</span><span class="operator">,</span> <span class="variable">tmp</span><span class="operator">,</span> <span class="variable">len</span><span class="operator">);</span>
     <span class="keyword">return</span> <span class="variable">len</span><span class="operator">;</span>
 <span class="operator">}</span>
</code></pre>

<h1 id="SEE-ALSO">SEE ALSO</h1>

<p><a href="../man3/EVP_EncryptInit.html">EVP_EncryptInit(3)</a>, <a href="../man3/EVP_BytesToKey.html">EVP_BytesToKey(3)</a>, <a href="../man7/passphrase-encoding.html">passphrase-encoding(7)</a></p>

<h1 id="HISTORY">HISTORY</h1>

<p>The old Netscape certificate sequences were no longer documented in OpenSSL 1.1.0; applications should use the PKCS7 standard instead as they will be formally deprecated in a future releases.</p>

<h1 id="COPYRIGHT">COPYRIGHT</h1>

<p>Copyright 2001-2019 The OpenSSL Project Authors. All Rights Reserved.</p>

<p>Licensed under the OpenSSL license (the &quot;License&quot;). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <a href="https://www.openssl.org/source/license.html">https://www.openssl.org/source/license.html</a>.</p>


</body>

</html>


